package leetcode;


import java.util.Stack;

/**
 * 用栈实现队列
 */
public class LeetCode232 {
    Stack<Integer> from = new Stack<>();
    Stack<Integer> to = new Stack<>();

    /** Initialize your data structure here. */
    public LeetCode232() {

    }

    /** Push element x to the back of queue. */
    public void push(int x) {
        from.push(x);
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        if (!to.isEmpty()) return to.pop();
        while (!from.isEmpty()) {
            to.push(from.pop());
        }
        if (!to.isEmpty()) return to.pop();
        return -1;
    }

    /** Get the front element. */
    public int peek() {
        if (!to.isEmpty()) return to.peek();
        while (!from.isEmpty()) {
            to.push(from.pop());
        }
        if (!to.isEmpty()) return to.peek();
        return -1;
    }

    /** Returns whether the queue is empty. */
    public boolean empty() {
        return to.isEmpty() && from.isEmpty();
    }
}